package com.alameda.controller.v1.user;

import com.alameda.common.result.Result;
import com.alameda.pojo.user.AdUserOrganizationDO;
import com.alameda.service.user.AdUserOrganizationService;
import com.alameda.user.dto.AdUserOrganizationDTO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 用户组织 前端控制层
 *
 * @author Lv
 * @date 2024/04/27
 */
@Api(tags = "用户组织")
@RestController
@RequestMapping("/ad_user_organization")
public class AdUserOrganizationController {

    @Autowired
    private AdUserOrganizationService adUserOrganizationService;

    /**
     * 查询组织列表
     *
     * @param adUserOrganizationDTO 用户组织信息
     * @return
     */
    @ApiOperation("查询组织列表")
    @PostMapping("/list_organization")
    public Result<?> listOrganization(@RequestBody AdUserOrganizationDTO adUserOrganizationDTO) {
        return Result.success(adUserOrganizationService.listOrganization(adUserOrganizationDTO));
    }

    /**
     * 新增或修改组织
     *
     * @param adUserOrganizationDO 用户组织实体
     * @return
     */
    @ApiOperation("新增或修改组织")
    @PostMapping("/save_or_update")
    public Result<?> saveOrUpdate(@RequestBody AdUserOrganizationDO adUserOrganizationDO) {
        return Result.success(adUserOrganizationService.saveOrUpdate(adUserOrganizationDO));
    }

    /**
     * 导出excel
     *
     * @param adUserOrganizationDTO 用户组织信息
     */
    @ApiOperation("导出excel")
    @PostMapping("/export")
    public void export(@RequestBody AdUserOrganizationDTO adUserOrganizationDTO) {
        adUserOrganizationService.export(adUserOrganizationDTO);
    }

    /**
     * 获取一级组织信息
     *
     * @param adUserOrganizationDTO 用户组织信息
     * @return
     */
    @ApiOperation("查询部门信息下拉列表")
    @PostMapping("/find_organization")
    public Result<?> findUserOrganization(@RequestBody AdUserOrganizationDTO adUserOrganizationDTO) {
        return Result.success(adUserOrganizationService.findUserOrganization(adUserOrganizationDTO));
    }

    /**
     * 删除组织信息
     *
     * @param idList 组织id集合
     * @return
     */
    @ApiOperation("删除组织信息")
    @PostMapping("/delete")
    public Result<?> deleteByIds(@RequestBody List<Long> idList) {
        return Result.success(adUserOrganizationService.deleteByIds(idList));
    }
}

